<?php
/**
 * SemesterTeacher Model
 *
 * Utilizes the Data Mapper pattern to persist data. Represents a single
 * semester_teacher entry
 *
 * @version $Id: SemesterTeacher.php 73 2010-04-25 00:30:44Z yingkuang.chen@gmail.com $
 * @license New BSD License
 * @uses Semester_Model_SemesterTeacherMapper
 * @package semester
 * @subpackage Model
 */
class Semester_Model_SemesterTeacher extends Semester_Model_Doctrine_BaseSemesterTeacher
{

  /**
   *  找出學期教師任教班級
   * @param integer| string $year
   * @param integer| null $semester
   * @return array
   */
  public function getTutors($year,$semester=null)
    {
        if ($semester == null){
            $temp = explode("-",$year);
            $year = $temp[0];
            $semester = $temp[1];
        }
        $q = $this->getTable()->createQuery('a')
        ->select('a.class_num, a.teacher_id, b.name AS name, b.sn AS sn')
        ->leftJoin('a.Teacher_Model_TeacherView  b')
        ->where('a.year=?',$year)
        ->andwhere('a.semester=?',$semester)
        ->andwhere('a.class_num>0');

        $res = $q->fetchArray();
        $arr = array();
        foreach($res as $row)
        $arr[$row['class_num']][] = $row;
//        print_r($arr); exit;
        return $arr;
    }
}
